/*
* $Id: Apiary.java 268 2011-02-14 08:03:19Z volok-aleksej@yandex.ru $
*
* Copyright 2008-2010 by Volokitin Alexey
* All rights reserved
*
*/
package apiary;

import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;

import apiary.ui.BackScreen;

/**
 * Main application class
 * @author lexus
 */
public class Apiary
{
//---------------Instance of Apiary----------------
    /** Instance class */
    private static Apiary app = null;
    /**
     * Gets instance class
     */
    public static Apiary getInstance(){
        if(app == null)
            System.err.print("application is null");
        return app;
    }

    /**
     * Constructor
     * @param mdlt midlet instance
     */
    public Apiary(MIDlet mdlt){
        app = this;
        midlet = mdlt;
        curDisplay = null;
        localeManager = LocaleManager.getInstance();
    }

    /** Current displayable form */
    private BackScreen curDisplay;
    /** Midlet instance */
    private MIDlet midlet;
    /** Localization manager */
    private LocaleManager localeManager;

//-----------------Apiary function-----------------
    /**
     * Exit application
     */
    public void exit() {
        midlet.notifyDestroyed();
    }
    /**
     * Sets active form and shows it
     * @param display form that will be displayed
     */
    public void Display(BackScreen display) {
        Display screen = Display.getDisplay(midlet);
        screen.setCurrent(display);
        curDisplay = display;
    }
    /**
     * Gets current displayable form
     * @return current displayable form
     */
    public Displayable getDisplay() {
        return curDisplay;
    }
    /**
     * Gets string that has been localized
     * @param name name string
     * @return localized string
     */
    public String getLocaleString(String name) {
        return localeManager.getLocaleString(name);
    }
}